package com.ladlee.validata.config;

import com.ladlee.properties.SecurityProperties;
import com.ladlee.validata.image.ImageCodeGenerator;
import com.ladlee.validata.sms.SmsCodeGenerator;
import com.ladlee.validata.sms.SmsCodeSender;
import com.ladlee.validata.sms.impl.DefaultSmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: dingchang
 * @Date: 2018/12/21 19:57
 * @Description: 验证码相关的扩展点配置。配置在这里的bean，业务系统都可以通过声明同类型或同名的bean来覆盖安全
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    SecurityProperties securityProperties;

    /**
     * 短信码生成器
     * @return
     */
    /*@Bean
    @ConditionalOnMissingBean(name = "smsValidateCodeGenerator")
    public SmsCodeGenerator smsValidateCodeGenerator(){
        SmsCodeGenerator generator = new SmsCodeGenerator();
        generator.setSecurityProperties(securityProperties);
        return generator;
    }*/

    /**
     * 图形码生成器
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ImageCodeGenerator imageValidateCodeGenerator(){
        ImageCodeGenerator generator = new ImageCodeGenerator();
        generator.setSecurityProperties(securityProperties);
        return generator;
    }

    /**
     * 短信验证码发送器
     */
    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender(){
        return new DefaultSmsCodeSender();
    }
}
